﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HelperClass;
using SHNOPData.SHNOPModel;
using SHNOPData.common;
namespace SHNOPData.ImportExcel
{
    public class ImportFactory
    {
        public ImportFactory()
        {

        }
        public void ImportStream(string type, Stream str)
        {
            string retMsg = "";
            string[,] array = ExcelHelper.ReadFromExcelsStream(str, ref retMsg, 0);
            if (array != null)
            {
                IImportExcel import = null;
                switch (type)
                {
                    case "0":
                        if (array.GetLength(1) == 41 && array[0, 4].Trim().Equals("工单号") && array[0, 40].Trim().Equals("物理站点名"))
                        {
                            import = new ImportZhandian();
                        }
                        else
                        {
                            retMsg = "模板格式不匹配";
                        }
                        break;
                    case "1":
                        if (array.GetLength(1) == 13 && array[0, 4].Trim().Equals("900M站点申请端口数") && array[0, 12].Trim().Equals("TD未完成端口分配原因"))
                        {
                            import = new ImportPort();
                        }
                        else
                        {
                            retMsg = "模板格式不匹配";
                        }
                       
                        break;
                    case "2":
                        if (array.GetLength(1) == 16 && array[0, 4].Trim().Equals("900M是否频率申请") && array[0, 15].Trim().Equals("TD工单号"))
                        {
                            import = new ImportPinLv();
                        }
                        else
                        {
                            retMsg = "模板格式不匹配";
                        }
                       
                        break;
                    case "3":
                        if (array.GetLength(1) == 19 && array[0, 4].Trim().Equals("G网站名") && array[0, 18].Trim().Equals("完成日期"))
                        {
                            import = new ImportRuwang();
                        }
                        else
                        {
                            retMsg = "模板格式不匹配";
                        }
                     
                        break;
                    case "4":
                        if (array.GetLength(1) == 22 && array[0, 5].Trim().Equals("协同平台工单号") && array[0, 21].Trim().Equals("加站目的"))
                        {
                            import = new ImportNtPlan();
                        }
                        else
                        {
                            retMsg = "模板格式不匹配";
                        }
                       
                        break;
                    default:
                        break;
                }
                if (import!=null)
                {
                    import.Import(array);
                }
                else
                {
                    System.Web.HttpContext.Current.Session["batchImport"] = retMsg;
                }
            }
            else
            {
                System.Web.HttpContext.Current.Session["batchImport"] = retMsg;
            }
           
            
        }
    }
}
